package com.test.controller;


import com.test.domain.Merchant;
import com.test.domain.Result;
import com.test.domain.User;
import com.test.domain.Utils;
import com.test.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/merchant")
public class MerchantController {

    private final MerchantService merchantService;

    @Autowired

    public MerchantController(MerchantService merchantService) {
        this.merchantService = merchantService;
    }

    //登录操作
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        System.out.println(user);
        int status  = merchantService.registerAndLogin(user);
        return Utils.success(status);
    }

    //个人信息获取
    @GetMapping("/info")
    public Result getInfo(@RequestParam("phoneNumber") String phoneNumber){
        System.out.println(phoneNumber);
        return Utils.success(merchantService.merchantInfo(phoneNumber));
    }

    @PostMapping("/updateShopName")
    public Result updateShopName(@RequestBody Merchant merchant){
        System.out.println(merchant);
        merchantService.updateShopName(merchant);
        return Utils.success("ok");
    }

    @PostMapping("/updateIsWorking")
    public Result updateIsWorking(@RequestBody Merchant merchant){
        System.out.println(merchant);
        merchantService.updateIsWorking(merchant);
        return Utils.success("ok");
    }

    @PostMapping("/updateShopDescription")
    public Result updateShopDescription(@RequestBody Merchant merchant){
        System.out.println(merchant);
        merchantService.updateShopDescription(merchant);
        return Utils.success("ok");
    }
}
